package com.chengshi.shop.controller.mobile.index;

import com.chengshi.shop.controller.common.BaseController;
import com.chengshi.shop.model.goods.Goods;
import com.chengshi.shop.model.index.IndexAd;
import com.chengshi.shop.model.index.IndexFloor;
import com.chengshi.shop.service.goods.GoodsService;
import com.chengshi.shop.service.index.IndexService;
import com.chengshi.shop.service.shop.ShopService;
import com.chengshi.shop.util.MessageUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 商城首页相关
 * @author xuxinlong
 * @version 2017年10月11日
 */
@Api(tags ="商城首页相关接口")
@RestController
@RequestMapping("/mobile/index")
public class MobileIndexController extends BaseController{
    @Resource
    private IndexService indexService;
    @Resource
    private ShopService shopService;
    @Resource
    private GoodsService goodsService;

    /**
     * 获取首页广告brand图
     * @return
     */
    @ApiOperation(value = "获取首页广告图列表")
    @GetMapping("/getAdList")
    public HashMap<String, Object> getAdList(){
        HashMap<String, Object> retMap = MessageUtils.success();
        try {
            List<IndexAd> adList = indexService.getValidAdList();
            retMap.put("list", adList);
        } catch (Exception e){
            retMap = MessageUtils.error();
        }
        return retMap;
    }

    /**
     * 获取首页楼层列表
     * @return
     */
    @ApiOperation(value = "获取首页楼层列表")
    @GetMapping("/getFloorList")
    public HashMap<String, Object> getFloorList(){
        HashMap<String, Object> retMap = MessageUtils.success();
        try {
            List<IndexFloor> floorList = indexService.getFloorList();
            retMap.put("list", floorList);
        } catch (Exception e){
            retMap = MessageUtils.error();
        }
        return retMap;
    }

    /**
     * 获取首页商品列表
     * @return
     */
    @ApiOperation(value = "获取首页商品列表")
    @GetMapping("/getGoodsList")
    public HashMap<String, Object> getGoodsList(){
        HashMap<String, Object> retMap = MessageUtils.success();
        try {
            HashMap<String, Object> inMap = new HashMap<>(2);
            inMap.put("isOnSale", 1);
            this.startPage();
            List<Goods> goodsList = goodsService.getGoodsList(inMap);
            retMap.put("data", new PageInfo<>(goodsList));
        } catch (Exception e){
            retMap = MessageUtils.error();
        }
        return retMap;
    }

    /**
     * 获取商城简介
     * @return
     */
    @ApiOperation(value = "获取商城简介")
    @GetMapping("/getShopIntro")
    public HashMap<String, Object> getShopIntro(){
        HashMap<String, Object> retMap = MessageUtils.success();
        try {
            String shopIntro = shopService.getShopConfig("SHOP_INTRO");
            retMap.put("shopIntro", shopIntro);
        } catch (Exception e){
            retMap = MessageUtils.error();
        }
        return retMap;
    }
}
